package dao

import (
	"gostore/model"
)

type SystemUserLevelT struct {
	DaoT
}

var SystemUserLevelDao = SystemUserLevelT{}

type ReqQuerySystemUserLevel struct {
	Query
	IsShow int    `form:"isShow" json:"isShow"` // 是否显示
	Name   string `form:"name" json:"name"`     // 任务名称
}

func (dao SystemUserLevelT) SystemUserLevelList(req *ReqQuerySystemUserLevel) (r []*model.SystemUserLevel, count int64, err error) {

	db := GetDB()

	if req.IsShow >= 0 {
		db = db.Where("is_show = ?", req.IsShow)
	}

	// @Todo 任务名称的搜索没有做

	limit := 10
	page := 0

	if req.Page > 0 {
		page = req.Page - 1
	}
	if req.PageNum > 0 {
		limit = req.PageNum
	}

	offset := limit * page

	r = make([]*model.SystemUserLevel, 0)

	err = db.Offset(offset).Limit(limit).Find(&r).Count(&count).Error
	if err != nil {
		return
	}
	return
}
